<?php
/**
 * Created by PhpStorm.
 * User: sen
 * Date: 16/7/13
 * Time: 下午4:18
 */
namespace app\controllers;
use app\models\bar_bar;
use yii\web\Controller;

class BackbaseController extends Controller{

    public function confirmBar(){

        if (!isset($_COOKIE["bar_id"])) {// 如果id 不存在的话就跳转到最开始的登录界面

            return $this->redirect('login');
        }else{

            if(!isset($_COOKIE["token"])){
                return $this->redirect('login');
            }

            $model = new bar_bar();
            $bar = $model->confirmBarToken($_COOKIE["bar_id"],$_COOKIE["token"]);

            if(!$bar){
                setcookie("bar_id",false,time() - 600,'/');
                setcookie("token",false,time() - 600,'/');
                setcookie("bar_name",false,time() - 600,'/');
                setcookie("bar_logo",false ,time() - 600,'/');
                setcookie("room_id",false,time() - 600,'/');
                setcookie("is_check",false ,time() - 600,'/');
                return $this->redirect('login');
            }
        }
    }

    public function getBarId(){
        return isset($_COOKIE["bar_id"])?$_COOKIE['bar_id']:"-1";
    }

    public function confirmAdmin(){

        if (!isset($_COOKIE["admin_id"])) {// 如果app_id 不存在的话就跳转到最开始的登录界面

            return $this->redirect(array('backstageapp/login'));
        }
    }

    public function getAdminId(){
        return isset($_COOKIE["admin_id"])?$_COOKIE['admin_id']:"-1";
    }
}